home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 January - Disc 2 / Macworld (1999-01) (Disk 2).dmg / Serious Demos / Symbolic Composer 4.2 / Environment / System / CADAR / Lengths / quantize < prev    next >
Lisp/Scheme  |  1998-10-22  |  699b  |  31 lines

  1. quantize length-list &rest quantize-levels
  2.  
  3. quantizes a length-list into closest
  4. level. length-list can be ticks or ratios. 
  5.  
  6. a few examples:
  7.  
  8. (setq rhy '(226 494 462 485 476 493 488 135 108 474 482))
  9.  
  10. (quantize rhy '1/24)
  11. ->(1/8 1/4 1/4 1/4 1/4 1/4 1/4 1/12 1/24 1/4 1/4)
  12.  
  13. (quantize rhy '1/20 '1/24 '1/28)
  14. ->(1/8 1/4 1/4 1/4 1/4 1/4 1/4 1/14 1/20 1/4 1/4)
  15.  
  16. (quantize rhy '1/64 '1/48)
  17. ->(1/8 1/4 15/64 1/4 1/4 1/4 1/4 1/16 1/16 1/4 1/4)
  18.  
  19. (setq rhy2 '(1/8 1/7 1/6 1/5 1/3))
  20.  
  21. (quantize rhy2 '1/8 '1/5)
  22. ->(1/8 1/8 1/5 1/5 3/8)
  23.  
  24. (defun randolph (l)
  25.    (+ (- (random 40) 20) l))
  26.  
  27. (setq rhy3 (mapcar #'randolph (mapcar #'get-tick rhy2)))
  28.  
  29. (quantize rhy3 '1/8 '1/7 '1/6 '1/5 '1/3) 
  30. ->(1/8 1/7 1/6 1/5 1/3)
  31.